package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-10-09
 * Time: 23:53
 */
public class demo3 {
    public static void main1(String[] args) {

        Thread t = new Thread(){
            @Override
            public void run() {

                while (true) {

                    System.out.println("这⾥是线程运⾏的代码");

                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };

        t.start();

        while (true) {

            System.out.println("这里是主线程");

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }


    public static void main(String[] args) {
        Thread t = new Thread(()->{
            while (true) {

                System.out.println("这⾥是线程运⾏的代码");

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"t1");

        t.start();

    }
}
